# ======================================================
# 			UNIVERSIDADE FEDERAL DE PERNANMBUCO
#
# MAKEFILE FOR PARALLEL OIL RESERVOIR SIMULATOR PROJECT
# Author: 	R. Soares
# Created:	2008-2010
# ======================================================

# Rogerio: rogsoares@yahoo.com.br

# flag for compilation
# ====================
#

# Use -DELIPTIC_SOLVER flag when evaluating pressure equation only. It means that getTotalMobility returns 1.0.
# Use -DCRUMPTON_EXAMPLE -DALPHA=1,10,100 or 1000 for Crumpton's cases
# Use -DBENCHMARK_3D for FVM benchmarks 

#CXXFLAGS=-DPARALLEL -g -Wall -D_SEEKFORBUGS_
#CXXFLAGS=-DPARALLEL -O3 -DCRUMPTON_EXAMPLE -DALPHA=1
#CXXFLAGS=-DPARALLEL -g -Wall -DBENCHMARK_3D 
#-DBENCHMARK3D_CASE3 -pg
CXXFLAGS=-DPARALLEL -O3  #-DONEQUARTER_OF_FIVESPOTS

PROJ_DIR=$(HOME)/programacao/projetos/PRS_1.1.5
APP_DIR=$(HOME)/applications

# compilers
# =========
CXX=mpicxx

# paths for headers
# =================
INCLUDES=-I$(APP_DIR)/FMDB-2011/include \
 	 	 -I$(APP_DIR)/autopack/include \
 	 	 -I$(PROJ_DIR)/include -I$(PROJ_DIR)/include/auxiliar \
 	 	 -I$(PROJ_DIR)/include/base_classes -I$(PROJ_DIR)/include/high_order_methods \
 	 	 -I$(PROJ_DIR)/include/EBFV1
 	 	 
# paths for libraries
# ===================
LIBS=-L$(APP_DIR)/FMDB-2011/lib -lFMDB-O \
     -L$(APP_DIR)/ParMetis-3.1/lib -lparmetis -lmetis \
     -L$(APP_DIR)/autopack/lib -lautopack-O

# path for where the objects must be put
# ======================================
OBJ_DIR=$(PROJ_DIR)/objs

# paths for each program source part
# ==================================
SRC_DIR1=$(PROJ_DIR)/src
SRC_DIR2=$(PROJ_DIR)/src/auxiliar
SRC_DIR3=$(PROJ_DIR)/src/elliptic-methods/EBFV1-ellipticEq
SRC_DIR4=$(PROJ_DIR)/src/elliptic-methods/EBFV1-ellipticEq/matrices_EFG
SRC_DIR5=$(PROJ_DIR)/src/IO_files
SRC_DIR6=$(PROJ_DIR)/src/hyperbolic-methods/EBFV1-hyperbolicEq
SRC_DIR7=$(PROJ_DIR)/src/hyperbolic-methods/EBFV1-hyperbolic-adaptative
SRC_DIR8=$(PROJ_DIR)/src/hyperbolic-methods/high_order

OBJECTS=$(OBJ_DIR)/main.o $(OBJ_DIR)/auxiliar.o $(OBJ_DIR)/SimulatorParameters.o \
		$(OBJ_DIR)/SIMULATION_core.o $(OBJ_DIR)/Exception.o $(OBJ_DIR)/exportVTK.o \
		$(OBJ_DIR)/PhysicPropData.o $(OBJ_DIR)/GeomData.o $(OBJ_DIR)/LoadSimulatorParameters.o \
		$(OBJ_DIR)/MeshData.o $(OBJ_DIR)/EBFV1_elliptic.o $(OBJ_DIR)/set_SOE.o \
		$(OBJ_DIR)/load_EBFV1_PreProcessorData.o $(OBJ_DIR)/EBFV1_E.o $(OBJ_DIR)/EBFV1_G.o \
		$(OBJ_DIR)/EBFV1_F_omega.o $(OBJ_DIR)/EBFV1_F_gamma.o $(OBJ_DIR)/EBFV1_pressure_gradient.o \
		$(OBJ_DIR)/EBFV1_hyperbolic.o $(OBJ_DIR)/EBFV1_hyperbolic-adaptative.o \
		$(OBJ_DIR)/EBFV1_velocityField.o $(OBJ_DIR)/EBFV1_advectiveTerm.o \
		$(OBJ_DIR)/explicit-advance.o $(OBJ_DIR)/OilProductionManagement.o \
		$(OBJ_DIR)/HighOrderApproximation.o $(OBJ_DIR)/SaturationGradient.o \
		$(OBJ_DIR)/SL__MUSCL.o $(OBJ_DIR)/SL__Woodfield.o $(OBJ_DIR)/Restart.o
		#\$(OBJ_DIR)/benchmark3d.o

		
# how the executable will be named
# ================================
EXEC=Reservoir-Simulator.exe

## top taget
all:	$(EXEC)

include ${PETSC_DIR}/bmake/common/base

$(EXEC):	$(OBJECTS) chkopts
	@echo "Linking objects..."
	@-$(CXX) -o $(EXEC) $(OBJECTS) -pg ${LIBS} ${PETSC_LIB}	

$(OBJ_DIR)/%.o:	$(SRC_DIR1)/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES)  -c $< ${PETSC_INCLUDE}
	@mv *.o $(OBJ_DIR)
	
$(OBJ_DIR)/%.o:	$(SRC_DIR2)/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES)  -c $< ${PETSC_INCLUDE}
	@mv *.o $(OBJ_DIR)
	
$(OBJ_DIR)/%.o:	$(SRC_DIR3)/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES)  -c $< ${PETSC_INCLUDE}
	@mv *.o $(OBJ_DIR)
	
$(OBJ_DIR)/%.o:	$(SRC_DIR4)/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES)  -c $< ${PETSC_INCLUDE}
	@mv *.o $(OBJ_DIR)
	
$(OBJ_DIR)/%.o:	$(SRC_DIR5)/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES)  -c $< ${PETSC_INCLUDE}
	@mv *.o $(OBJ_DIR)
	
$(OBJ_DIR)/%.o:	$(SRC_DIR6)/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES)  -c $< ${PETSC_INCLUDE}
	@mv *.o $(OBJ_DIR)
	
$(OBJ_DIR)/%.o:	$(SRC_DIR7)/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES)  -c $< ${PETSC_INCLUDE}
	@mv *.o $(OBJ_DIR)
	
$(OBJ_DIR)/%.o:	$(SRC_DIR8)/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES)  -c $< ${PETSC_INCLUDE}
	@mv *.o $(OBJ_DIR)
	

rebuild:
	@rm -f $(OBJ_DIR)/*.o $(EXEC)
	@echo "Limpeza concluida"
	@make
